<?php
namespace App\Http\Admin\ProcessProduct\Controllers;


use Framework\BaseClass\Http\Admin\Controller;
use App\Eloquent\Ygt\ProcessProduct as ProcessProductModel;


class IndexController extends Controller
{
    protected $company = false;

    public function __construct()
    {
        parent::__construct();
    }

    public function lists(){
        $adminUser         = request()->user('admin')->toArray();
        $companyId         = $adminUser['company_id'];

        if (request()->isMethod('post')) {
            $title         = request( 'title', '' );

            $obj = new ProcessProductModel();
            $obj = $obj->where('company_id','=',$companyId);
            if(!empty($title)){
                $obj = $obj->where("title",'=',$title);
            }

            $fields = [
                'id','title','number','in_number','out_number'
            ];

            $lists = $obj->orderBy('id','desc')->get($fields)->toArray();
            $result         = collect($lists)->toJson();
            return $result;
        } else {

            $toolbarItem       = '';
            $obj = new ProcessProductModel();
            $obj = $obj->where('company_id','=',$companyId);
            $fields = [
                'id','title','number','in_number','out_number'
            ];

            $obj->orderBy('id','desc')->get($fields)->toArray();
            return $this->view('lists', compact('toolbarItem') );
        }
    }

}